<?php
/**
 * PHP file wsp\includes\utils2.inc.php
 */
/**
 * WebSite-PHP file utils2.inc.php
 *
 * WebSite-PHP : PHP Framework 100% object (http://www.website-php.com)
 * Copyright (c) 2009-2015 WebSite-PHP.com
 * PHP versions >= 5.2
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @author      Emilien MOREL <admin@website-php.com>
 * @link        http://www.website-php.com
 * @copyright   WebSite-PHP.com 14/12/2014
 * @version     1.2.11
 * @access      public
 * @since       1.2.0
 */

	function url_rewrite_format($car, $disable_utf8decode=false){
		if (!$disable_utf8decode && function_exists("is_utf8") && is_utf8($car)) {
			$car = utf8_decode($car);
		}
		$car=html_entity_decode($car);
		$string= array("'" => "_", "(" => "_", ")" => "_", "*" => "_", 
			"+" => "_", "," => "_", "-" => "_", "." => "_", 
			"/" => "_", ":" => "_", ";" => "_", "<" => "_", 
			"=" => "_", ">" => "_", "?" => "_", "@" => "_", 
			"[" => "_", "\\" => "_", "]" => "_", "^" => "_", 
			"`" => "_", "{" => "_", "|" => "_", "}" => "_", 
			"~" => "_", "\x7F" => "_", "\x80" => "_", "\x81" => "_", 
			"\x82" => "_", "\x83" => "_", "\x84" => "_", "\x85" => "_", 
			"\x86" => "_", "\x87" => "_", "\x88" => "_", "\x89" => "_", 
			"\x8A" => "s", "\x8B" => "_", "\x8C" => "oe", "\x8D" => "_", 
			"\x8E" => "Z", "\x8F" => "_", "\x90" => "_", "\x91" => "_", 
			"\x92" => "_", "\x93" => "_", "\x94" => "_", "\x96" => "_", 
			"\x96" => "_", "\x97" => "_", "\x98" => "_", "\x99" => "_", 
			"\x9A" => "s", "\x9B" => "_", "\x9C" => "_", "\x9D" => "z", 
			"\x9F" => "y", " " => "_", "\xA0" => "_", "\xA1" => "i", "\xA2" => "c", 
			"\xA3" => "l", "\xA4" => "_", "\xA5" => "y", "\xA6" => "_", 
			"\xA7" => "_", "\xA8" => "_", "\xA9" => "_", "\xAA" => "_", 
			"\xAB" => "_", "\xAC" => "_", "\xAD" => "_", "\xAE" => "_", 
			"\xAF" => "_", "\xB0" => "_", "\xB1" => "_", "\xB2" => "_", 
			"\xB3" => "_", "\xB4" => "_", "\xB5" => "u", "\xB6" => "_", 
			"\xB7" => "_", "\xB8" => "_", "\xB9" => "_", "\xBA" => "_", 
			"\xBB" => "_", "\xBC" => "_", "\xBD" => "_", "\xBE" => "_", 
			"\xBF" => "_", "\xC0" => "A", "\xC1" => "A", "\xC2" => "A", 
			"\xC3" => "A", "\xC4" => "A", "\xC5" => "A", "\xC6" => "AE", 
			"\xC7" => "C", "\xC8" => "E", "\xC9" => "E", "\xCA" => "E", 
			"\xCB" => "E", "\xCC" => "I", "\xCD" => "I", "\xCE" => "I", 
			"\xCF" => "I", "\xD0" => "D", "\xD1" => "N", "\xD2" => "O", 
			"\xD3" => "O", "\xD4" => "O", "\xD5" => "O", "\xD6" => "O", 
			"\xD7" => "x", "\xD8" => "O", "\xD9" => "U", "\xDA" => "U", 
			"\xDB" => "U", "\xDC" => "U", "\xDD" => "Y", "\xDE" => "_", 
			"\xDF" => "s", "\xE0" => "a", "\xE1" => "a", "\xE2" => "a", 
			"\xE3" => "a", "\xE4" => "a", "\xE5" => "a", "\xE6" => "ae", 
			"\xE7" => "c", "\xE8" => "e", "\xE9" => "e", "\xEA" => "e", 
			"\xEB" => "e", "\xEC" => "i", "\xED" => "i", "\xEE" => "i", 
			"\xEF" => "i", "\xF0" => "_", "\xF1" => "n", "\xF2" => "o", 
			"\xF3" => "o", "\xF4" => "o", "\xF5" => "o", "\xF6" => "o", 
			"\xF7" => "_", "\xF8" => "o", "\xF9" => "u", "\xFA" => "u", 
			"\xFB" => "u", "\xFC" => "u", "\xFD" => "y", "\xFE" => "_", 
			"\xFF" => "y", "&" => "_", "\"" => "_", "!" => "_", "\r" => "_",
			"&" => "_", "#" => "_", "$" => "_", "%" => "_", "\n" => "_",
			"€" => "_", "‚" => "_", "ƒ" => "_", "„" => "_", "…" => "_",
			"†" => "_", "‡" => "_", "ˆ" => "_", "‰" => "_",
			"Š" => "s", "‹" => "_", "Œ" => "oe", "Ž" => "Z", "‘" => "_",
			"’" => "_", "“" => "_", "”" => "_", "•" => "_",
			"–" => "_", "—" => "_", "˜" => "_", "™" => "_",
			"š" => "s", "›" => "_", "ž" => "z",
			"Ÿ" => "y", " " => "_", "¡" => "i", "¢" => "c",
			"£" => "l", "¤" => "_", "¥" => "y", "¦" => "_",
			"§" => "_", "¨" => "_", "©" => "_", "ª" => "_",
			"«" => "_", "¬" => "_", "­" => "_", "®" => "_",
			"¯" => "_", "°" => "_", "±" => "_", "²" => "_",
			"³" => "_", "´" => "_", "µ" => "u", "¶" => "_",
			"·" => "_", "¸" => "_", "¹" => "_", "º" => "_",
			"»" => "_", "¼" => "_", "½" => "_", "¾" => "_",
			"¿" => "_", "À" => "A", "Á" => "A", "Â" => "A",
			"Ã" => "A", "Ä" => "A", "Å" => "A", "Æ" => "AE",
			"Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E",
			"Ë" => "E", "Ì" => "I", "Í" => "I", "Î" => "I",
			"Ï" => "I", "Ð" => "D", "Ñ" => "N", "Ò" => "O",
			"Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O",
			"×" => "x", "Ø" => "O", "Ù" => "U", "Ú" => "U",
			"Û" => "U", "Ü" => "U", "Ý" => "Y", "Þ" => "_",
			"ß" => "s", "à" => "a", "á" => "a", "â" => "a",
			"ã" => "a", "ä" => "a", "å" => "a", "æ" => "ae",
			"ç" => "c", "è" => "e", "é" => "e", "ê" => "e",
			"ë" => "e", "ì" => "i", "í" => "i", "î" => "i",
			"ï" => "i", "ð" => "_", "ñ" => "n", "ò" => "o",
			"ó" => "o", "ô" => "o", "õ" => "o", "ö" => "o",
			"÷" => "_", "ø" => "o", "ù" => "u", "ú" => "u",
			"û" => "u", "ü" => "u", "ý" => "y", "þ" => "_",
			"ā"=>"a", "Ā"=>"A", "Î"=>"I", "î"=>"i", "ç"=>"c", "è"=>"e", 
			"é"=>"e", "Œ"=>"OE", "œ"=>"oe", "ī"=>"i", "ă"=>"a", "ţ"=>"t",
			"ș"=>"s", "Ō"=>"o", "ō"=>"o", "ą"=>"a", "ş"=>"s", "Ś"=>"S",
			"Ş"=>"s", "Ł"=>"L", "ł"=>"l", "ź"=>"z", "Ź"=>"Z", "Ţ"=>"T",
			"Ī"=>"I", "Ą"=>"A", "Ș"=>"S", "Ă"=>"A", "ū"=>"u", "Ū"=>"U",
			"ŏ"=>"o", "Ŏ"=>"O", "Ḩ"=>"H", "ḩ"=>"h", "ę"=>"e", "Ę"=>"E",
			"İ"=>"I", "i̇"=>"i", "ě"=>"e", "Ě"=>"E", "č"=>"c", "Č"=>"C",
			"ż"=>"z", "Ż"=>"Z", "ő"=>"o", "Ő"=>"O", "ğ"=>"g", "Ğ"=>"G",
			"ė"=>"e", "Ė"=>"E", "ř"=>"r", "Ř"=>"R", "ı"=>"i", "ś"=>"s", 
			"ń"=>"n", "Ń"=>"N", "ÿ"=>"y", "Ÿ"=>"Y",
			/* Russian charaters */
			"А"=>"a", "Б"=>"b", "В"=>"v", "Г"=>"g", "Д"=>"d",
		    "Е"=>"e", "Ё"=>"yo", "Ж"=>"zh", "З"=>"z", "И"=>"i", 
		    "Й"=>"j", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n", 
		    "О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t", 
		    "У"=>"u", "Ф"=>"f", "Х"=>"kh", "Ц"=>"ts", "Ч"=>"ch", 
		    "Ш"=>"sh", "Щ"=>"sch", "Ъ"=>"", "Ы"=>"y", "Ь"=>"", 
		    "Э"=>"e", "Ю"=>"yu", "Я"=>"ya", "а"=>"a", "б"=>"b", 
		    "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"yo", 
		    "ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k", 
		    "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", 
		    "р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", 
		    "х"=>"kh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch", 
		    "ъ"=>"", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya");
			
		$car = strtr($car, $string);
		$car = stripslashes($car);
		
		$car = str_replace("__", "_", $car);
		$car = str_replace("__", "_", $car);
		$car = str_replace("__", "_", $car);
		if ($car[strlen($car)-1]=="_") {
			$car = substr($car, 0, strlen($car)-1);
		}
		$car = str_replace("_", "-", $car);
		return strtolower($car);
	}
	
	$html_convert_table = array (
	    "&" => "&amp;", "\xA1" => "&iexcl;", "\xA2" => "&cent;", "\xA3" => "&pound;", "\xA4" => "&curren;", "\xA5" => "&yen;",
	    "\xA6" => "&brvbar;", "\xA7" => "&sect;", "\xA8" => "&uml;", "\xA9" => "&copy;", "\xAA" => "&ordf;", "\xAB" => "&laquo;",
	    "\xAC" => "&not;", "\xAD" => "&shy;", "\xAE" => "&reg;", "\xAF" => "&macr;", "\xB0" => "&deg;", "\xB1" => "&plusmn;",
	    "\xB2" => "&sup2;", "\xB3" => "&sup3;", "\xB4" => "&acute;", "\xB5" => "&micro;", "\xB6" => "&para;", "\xB7" => "&middot;",
	    "\xB8" => "&cedil;", "\xB9" => "&sup1;", "\xBA" => "&ordm;", "\xBB" => "&raquo;", "\xBC" => "&frac14;", "\xBD" => "&frac12;",
	    "\xBE" => "&frac34;", "\xBF" => "&iquest;", "\xC0" => "&Agrave;", "\xC1" => "&Aacute;", "\xC2" => "&Acirc;", "\xC3" => "&Atilde;",
	    "\xC4" => "&Auml;", "\xC5" => "&Aring;", "\xC6" => "&AElig;", "\xC7" => "&Ccedil;", "\xC8" => "&Egrave;", "\xC9" => "&Eacute;",
	    "\xCA" => "&Ecirc;", "\xCB" => "&Euml;", "\xCC" => "&Igrave;", "\xCD" => "&Iacute;", "\xCE" => "&Icirc;", "\xCF" => "&Iuml;",
	    "\xD0" => "&ETH;", "\xD1" => "&Ntilde;", "\xD2" => "&Ograve;", "\xD3" => "&Oacute;", "\xD4" => "&Ocirc;", "\xD5" => "&Otilde;",
	    "\xD6" => "&Ouml;", "\xD7" => "&times;", "\xD8" => "&Oslash;", "\xD9" => "&Ugrave;", "\xDA" => "&Uacute;", "\xDB" => "&Ucirc;",
	    "\xDC" => "&Uuml;", "\xDD" => "&Yacute;", "\xDE" => "&THORN;", "\xDF" => "&szlig;", "\xE0" => "&agrave;", "\xE1" => "&aacute;",
	    "\xE2" => "&acirc;", "\xE3" => "&atilde;", "\xE4" => "&auml;", "\xE5" => "&aring;", "\xE6" => "&aelig;", "\xE7" => "&ccedil;",
	    "\xE8" => "&egrave;", "\xE9" => "&eacute;", "\xEA" => "&ecirc;", "\xEB" => "&euml;", "\xEC" => "&igrave;", "\xED" => "&iacute;",
	    "\xEE" => "&icirc;", "\xEF" => "&iuml;", "\xF0" => "&eth;", "\xF1" => "&ntilde;", "\xF2" => "&ograve;", "\xF3" => "&oacute;",
	    "\xF4" => "&ocirc;", "\xF5" => "&otilde;", "\xF6" => "&ouml;", "\xF7" => "&divide;", "\xF8" => "&oslash;", "\xF9" => "&ugrave;",
	    "\xFA" => "&uacute;", "\xFB" => "&ucirc;", "\xFC" => "&uuml;", "\xFD" => "&yacute;", "\xFE" => "&thorn;", "\xFF" => "&yuml;",
	    "\"" => "&quot;", "<" => "&lt;", ">" => "&gt;"
	);
?>
